import Vue from 'vue'
// 歌曲时长过滤器
Vue.filter('durationFormat', (time) => {
  if (typeof time === 'undefined') return 0
  let minutes = parseInt(time / 60) // 获取时长分钟
  let seconds = parseInt(time % 60) // 获取时长秒数
  seconds = seconds < 10 ? '0' + seconds : seconds // 秒
  minutes = minutes < 10 ? '0' + minutes : minutes
  return minutes + ':' + seconds
})

// 播放数量过滤器
Vue.filter('playtime', (count) => {
  if (typeof count === 'undefined') return 0
  if (count < 10000) return count
  else return Math.floor(count / 10000) + '万'
})

// 日期过滤器
Vue.filter('dateFormat', (timestamp) => {
  const date = new Date(timestamp)
  const year = date.getFullYear()
  let mouth = date.getMonth() + 1
  let day = date.getDate()
  mouth = mouth < 10 ? '0' + mouth : mouth
  day = day < 10 ? '0' + day : day
  return year + '-' + mouth + '-' + day
})
// 歌手名字拼接
Vue.filter('showArtist', function (value) {
  if (!value) return ''
  const artist = value.map(item => item.name).join(' / ')
  return artist
})
